# coding=utf-8
"""

"""
import logging
import os
from logging.handlers import TimedRotatingFileHandler

# @Time    :  2024-09-19 18:13:11
# @Author  :  jiangtong
# @Email   :  gingerqgyy@outlook.com
# @Project :  test_curl_convert
# @File    :  do_log

LOG_FILE = os.sep.join([os.path.dirname(os.path.dirname(__file__)), 'app', 'static', 'logs', 'curl_conversion.log'])
LOG_DEBUG_FILE = os.sep.join([os.path.dirname(os.path.dirname(__file__)), 'app', 'static', 'logs', 'curl_conversion_debug.log'])


def log():
    _t_log = logging.getLogger('curl_conversion')
    _t_log.setLevel(logging.DEBUG)

    console = logging.StreamHandler()
    console.setLevel(logging.DEBUG)
    console.setFormatter(logging.Formatter('[ %(asctime)s ] [ %(threadName)s ] ---> %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
    _t_log.addHandler(console)

    filehandler = TimedRotatingFileHandler(LOG_FILE, when='H', interval=1, backupCount=3, encoding='utf8')
    # filehandler.suffix = "%Y-%m-%d_%H"

    # 因为设置了开机自启动， 所以日志等级需要设置成 DEBUG, 让文件记录更多的数据, 遇到问题也方便排查
    filehandler.setLevel(logging.DEBUG)
    filehandler.setFormatter(logging.Formatter('[ %(asctime)s ] [ %(threadName)s ] ---> %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
    _t_log.addHandler(filehandler)
    return _t_log


def debug_log():
    _t_log = logging.getLogger('curl_conversion_debug')
    _t_log.setLevel(logging.DEBUG)

    console = logging.StreamHandler()
    console.setLevel(logging.DEBUG)
    console.setFormatter(logging.Formatter('[ %(asctime)s ] [ %(threadName)s ] ---> %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
    _t_log.addHandler(console)

    filehandler = TimedRotatingFileHandler(LOG_DEBUG_FILE, when='D', interval=1, backupCount=2, encoding='utf8')
    filehandler.suffix = "%Y-%m-%d_%H"

    # 因为设置了开机自启动， 所以日志等级需要设置成 DEBUG, 让文件记录更多的数据, 遇到问题也方便排查
    filehandler.setLevel(logging.DEBUG)
    filehandler.setFormatter(logging.Formatter('[ %(asctime)s ] [ %(threadName)s ] ---> %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
    _t_log.addHandler(filehandler)
    return _t_log


c_log = log()
local_log = c_log
# local_log = debug_log()
